package com.michau.testitas.core.server.service;

import com.michau.testitas.common.model.answer.Answer;
import com.michau.testitas.common.model.definition.Definition;
import com.michau.testitas.common.model.testentity.TestEntity;
import com.michau.testitas.common.service.TestEntityService;
import com.michau.testitas.core.dao.api.TestEntityDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * User: michau
 * Date: 3/1/13
 * Time: 5:05 PM
 */
@Transactional
@Service("testEntityService")
public class TestEntityServiceImpl implements TestEntityService {

    private Log log = LogFactory.getLog(TestEntityServiceImpl.class);

    @Autowired
    private TestEntityDao testEntityDao;

    @Override
    public TestEntity getById(final long id) {
        return testEntityDao.getById(id);
    }

    @Override
    public TestEntity getByTransferKey(String transferKey) {
        return testEntityDao.getByTransferKey(transferKey);
    }

    @Override
    public Set<TestEntity> getAll() {
        return testEntityDao.getAll();
    }

    @Override
    public TestEntity create(TestEntity testEntity) {
        return testEntityDao.create(testEntity);
    }

    @Override
    public void createOrUpdate(TestEntity testEntity) {
        testEntityDao.createOrUpdate(testEntity);
    }

    @Override
    public void copy(TestEntity fromTestEntity, TestEntity toTestEntity) {
        if (fromTestEntity != null){
            toTestEntity.setDefinition(fromTestEntity.getDefinitions());
            toTestEntity.setAnswer(fromTestEntity.getAnswer());
        }
    }

    @Override
    public void update(TestEntity testEntity) {
        testEntityDao.update(testEntity);
    }

    @Override
    public void delete(TestEntity... testEntity) {
        testEntityDao.delete(testEntity);
    }

    @Override
    public void deleteAll() {
        testEntityDao.deleteAll();
    }
}
